// 产品参数组件
<template>
  <div class="nav-bar" :class="{'is_fixed': isFixed}">
    <div class="container">
      <div class="pro-title">{{title}}</div>
      <div class="pro-param">
        <a href="javascript:;">概述</a>
        <span>|</span>
        <a href="javascript:;">参数</a>
        <span>|</span>
        <a href="javascript:;">用户评价</a>
        <slot name="buy"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NavBar',
  props: {
    title: String
  },
   data () {
    return {
      isFixed: false
    };
  },
  mounted () {
    window.addEventListener('scroll', this.initHeight);
  },
  destroyed () {
    // 第三个参数，事件行为的处理方式：true捕获(默认)，false：冒泡
    window.removeEventListener('scroll', this.initHeight, false);
  },
  methods: {
    initHeight () {
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      this.isFixed = scrollTop > 152 ? true : false;
    }
  },
}
</script>

<style lang="stylus" scoped>
@import '../assets/stylus/base.styl';
@import '../assets/stylus/config.styl';
@import '../assets/stylus/mixin.styl';

.nav-bar {
  setHeight(70px)
  border-top: 1px solid $colorJ;
  z-index: 10;
  &.is_fixed {
    // 添加固定定位的容器会变成行内元素，不再是块元素
    position: fixed;
    top: 0;
    width: 100%;
    background-color: $colorG;
    box-shadow: 0 5px 5px $colorE;
  }
  .container {
    setFlex();

    .pro-title {
      font-size: $fontH;
      color: $colorB;
      font-weight: bold;
    }

    .pro-param {
      font-size: $fontJ;

      span {
        margin: 0 10px;
      }

      a {
        color: $colorC;
      }
    }
  }
}
</style>